package com.sskj.hangqing.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.LanguageUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.hangqing.bean.BorrowRule;
import com.sskj.hangqing.bean.GuideListBean;
import com.sskj.hangqing.http.HttpConfig;
import com.sskj.hangqing.ui.activity.GuideWebActivity;
import com.sskj.lib.http.JsonCallBack;

import java.util.Locale;


public class GuideWebActivityPresenter extends BasePresenter<GuideWebActivity> {
    public void getContent(String id) {
        httpService.getGonggaoInfo(id)
                .execute(new JsonCallBack<HttpData<GuideListBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<GuideListBean>> response) {
                        HttpData<GuideListBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.getContentSuccess(httpData.getData());
                        }
                    }
                });
    }

    public void getXieyi(String xieyi) {
        httpService.getXieyi(xieyi)
                .execute(new JsonCallBack<HttpData<String>>() {
                    @Override
                    public void onSuccess(Response<HttpData<String>> response) {
                        HttpData<String> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateContent(httpData.getData());
                        }
                    }
                });
    }


    public void borrow() {
        httpService.borrowRule()
                .execute(new JsonCallBack<HttpData<BorrowRule>>() {
                    @Override
                    public void onSuccess(Response<HttpData<BorrowRule>> response) {
                        HttpData<BorrowRule> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            if (LanguageUtil.getAppLocale(App.INSTANCE) == Locale.ENGLISH) {
                                mView.updateContent(httpData.getData().getRule_en());
                            } else {
                                mView.updateContent(httpData.getData().getRule());
                            }
                        }
                    }
                });
    }
}
